/**************************************************************************
 * @name:  002_冒泡排序.c
 * @brief: 这是冒泡排序代码案例
 * @date:  2025/01/02
 * @author: boluzs@163.com
 * @note: None
 * @version: 1.0.0
 * @Copyright (c) 2025 by boluzs@163.com, All Rights Reserved.
 **************************************************************************/
#include <stdio.h>
#include <stdbool.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>

void BubbleSort(int *buf, int size)
{
    int i = 0, j = 0;
    int temp = 0;

    for (i = 0; i < size; i++)
    {
        for (j = size - 1; j > 0; j--)
        {
            if (buf[j] < buf[j - 1])
            {
                temp = buf[j];
                buf[j] = buf[j - 1];
                buf[j - 1] = temp;
            }
        }
    }

    // for (i = size - 1; i > 0; i--)
    // {
    //     for (j = 0; j < i; j++)
    //     {
    //         if (buf[j] > buf[j + 1])
    //         {
    //             temp = buf[j];
    //             buf[j] = buf[j + 1];
    //             buf[j + 1] = temp;
    //         }
    //     }
    // }
}

int main()
{
    int *arr = calloc(1, sizeof(int) * 8);
    arr[0] = 3;
    arr[1] = 6;
    arr[2] = 2;
    arr[3] = 1;
    arr[4] = 8;
    arr[5] = 7;
    arr[6] = 5;
    arr[7] = 4;
    BubbleSort(arr, 8);
    for (int i = 0; i < 8; i++)
    {
        printf("%d ", arr[i]);
    }
    printf("\n");
    free(arr);
    return 0;
}